package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        String s1 = "abc";
        String s2 = "abc";
        System.out.println("s1"+s1);
        System.out.println("s2"+s2);

        Class cls = String.class;
        Field field = cls.getDeclaredField("value");//Field是反射对象之一，用于表示一个属性
        field.setAccessible(true);
        field.set(s1 ,new char[]{'d','e','f',});//str.value = new char['d','e','f'];
        field.setAccessible(false);

        String s3 = "abc";//因为常量池的缘故，依然重用了s1对象
        System.out.println("s3"+s3);//输出def
    }
}
